<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>生成申报方案用户</title>
<link rel="stylesheet" type="text/css" href="../css/blueprint/screen.css" media="screen, projection"/>
<link rel="stylesheet" type="text/css" href="../css/blueprint/plugins/buttons/screen.css" media="screen, projection"/>
<script type="text/javascript" src="../script/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="../script/sha1.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
    	prepare();
        $("#SAVE_BUTTON").click(function() {
            if ($("#USERID_TEXT").val() == "") {
                alert("用户名不能为空");
                return false;
            }
            if ($("#USERPASS_TEXT").val() == "") {
                alert("密码不能为空");
                return false;
            }
            $.ajax({
                url: "SavePlanUser.action",
                type: "post",
                dataType: "json",
                data:
                {
                    "planUser.username": $("#USERID_TEXT").val(),
                    "planUser.password": hex_sha1($("#USERPASS_TEXT").val()),
                    "planUser.unitId": $("#unit_select").val(),
                    "planUser.unitName": $("#unit_select option:selected").text(),
                    "planUser.enabled": $("#ENABLED_CHECKBOX").is(":checked") ? "1" : "0"
                },
                success: function(data) {
                    if (data.saveStatus == "error") {
                    	alert("保存用户失败");
                    } else if (data.saveStatus == "same username") {
                    	$("#username_state").text("用户名已被占用").addClass("notice");
                    } else if (data.saveStatus == "success") {
                        $("#state").text("保存用户成功").addClass("success");
                        window.location.href = "ManagePlanUser.html";
                    }
                }
            });
        });
    });
    function prepare() {
        $.ajax({
            type: "post",
            url:  "LoadAllUnit.action",
            dataType: "json",
            success: function(data) {
                var strArr = new Array();
                for (var i = 0; i < data.unitList.length; i++) {
                    strArr.push('<option value="' + data.unitList[i].unitId + '">' + data.unitList[i].unitName + '</option>');
                }
                strArr.push('<option value="999">其他</option>');
                $("#unit_select").html(strArr.join(''));
            }
        });
    }
</script>
</head>
<body>
<div class="span-20 prepend-1">
    <div class="span-20">用户名：<input type="text" id="USERID_TEXT"/><span id="username_state"></span></div>
    <div class="span-20">密&nbsp;&nbsp;&nbsp;&nbsp;码：<input type="text" id="USERPASS_TEXT"/></div>
    <div class="span-20">编制单位：<select id="unit_select"></select></div>
    <div class="span-20">启&nbsp;&nbsp;&nbsp;&nbsp;用：<input type="checkbox" id="ENABLED_CHECKBOX"/></div>
    <br/>
    <div class="span-20"><button type="button" id="SAVE_BUTTON"><img src="../css/blueprint/plugins/buttons/icons/disk.png" alt=""/>保存申报用户</button><span id="state"></span></div>
</div>
</body>
</html>